package mylab.io.base.util;

import java.net.InetSocketAddress;
import java.net.URI;

import lombok.experimental.UtilityClass;
import mylab.io.base.model.Endpoint;
import mylab.io.base.model.impl.SocketEndpoint;
import mylab.io.base.model.Terminal;

@UtilityClass
public class TerminalUtil {

    public boolean isValid(Terminal terminal) {
        return terminal != null && terminal.getId() != null;
    }

    public Terminal socketTerminal(String ip, int port) {
        SocketEndpoint endpoint = new SocketEndpoint(ip, port);
        return new Terminal(endpoint);
    }

    public Terminal socketTerminal(InetSocketAddress address) {
        SocketEndpoint endpoint = new SocketEndpoint(address.getHostName(), address.getPort());
        return new Terminal(endpoint);
    }

    public Terminal socketTerminal(URI uri) {
        return socketTerminal(uri.getHost(), uri.getPort());
    }

    public Terminal socketTerminal(Endpoint endpoint) {
        return new Terminal(endpoint);
    }

    public Terminal rxtxTerminal(Endpoint endpoint) {
        return new Terminal(endpoint);
    }


}
